package com.sigerap.mesa.model.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.sigerap.comanda.model.Comanda;
import com.sigerap.mesa.model.Mesa;
import com.sigerap.mesa.model.dao.MesaDAO;
/**
 * 
 * @author Spirit-20121
 *
 */
public class JPAMesaDAO implements MesaDAO{
	
	private EntityManager em;
	
	public JPAMesaDAO(EntityManager em){
		this.em = em;
	}

	@Override
	public List<Mesa> findAll() {
		Query query = em.createQuery("Select m.codMesa From Mesa m where m.Estado='I'");
		return query.getResultList();
	}

	@Override
	public Comanda findByMesa(Mesa mesa) {
		Query query = em.createQuery("Select c From Comanda c where c.codMesa='"+mesa.getCodMesa()+"'");
		return (Comanda) query.getSingleResult();
	}

}
